/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.linker.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedList;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author xljan
 */
@Entity
@Table(name = "linker_category")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = LinkerCategory.NQ_FIND_BY_NAME, 
        query = "SELECT l FROM LinkerCategory l WHERE l.name = :name"),
    @NamedQuery(name = LinkerCategory.NQ_FIND_ROOT, 
        query = "SELECT l FROM LinkerCategory l WHERE l.parent IS NULL"),
    @NamedQuery(name = LinkerCategory.NQ_FIND_BY_PARENT, 
        query = "SELECT l FROM LinkerCategory l WHERE l.parent = :parent")})
public class LinkerCategory implements Serializable {
    public static final String NQ_FIND_BY_PARENT = 
            "LinkerCategory.findByParent";
    public static final String NQ_FIND_ROOT = "LinkerCategory.findRoot";
    public static final String NQ_FIND_BY_NAME = "LinkerCategory.findByName";
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_category")
    private Integer idCategory = 0;
    @Size(max = 255)
    @Column(name = "name")
    private String name;
    @Column(name = "priority")
    private Integer priority;
    @OneToMany(mappedBy = "parent", cascade= CascadeType.ALL)
    private Collection<LinkerCategory> linkerCategoryCollection = new LinkedList<LinkerCategory>();
    @JoinColumn(name = "parent", referencedColumnName = "id_category")
    @ManyToOne
    private LinkerCategory parent;
    @OneToMany(mappedBy = "idCategory", cascade= CascadeType.ALL)
    private Collection<LinkerLink> linkerLinkCollection = new LinkedList<LinkerLink>();

    public LinkerCategory() {
    }

    public LinkerCategory(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public Integer getIdCategory() {
        return idCategory;
    }

    public void setIdCategory(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    @XmlTransient
    public Collection<LinkerCategory> getLinkerCategoryCollection() {
        return linkerCategoryCollection;
    }

    public void setLinkerCategoryCollection(Collection<LinkerCategory> linkerCategoryCollection) {
        this.linkerCategoryCollection = linkerCategoryCollection;
    }

    public LinkerCategory getParent() {
        return parent;
    }

    public void setParent(LinkerCategory parent) {
        this.parent = parent;
    }

    public Collection<LinkerLink> getLinkerLinkCollection() {
        return linkerLinkCollection;
    }

    public void setLinkerLinkCollection(Collection<LinkerLink> linkerLinkCollection) {
        this.linkerLinkCollection = linkerLinkCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCategory != null ? idCategory.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LinkerCategory)) {
            return false;
        }
        LinkerCategory other = (LinkerCategory) object;
        if ((this.idCategory == null && other.idCategory != null) || (this.idCategory != null && !this.idCategory.equals(other.idCategory))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fyx.linker.entity.LinkerCategory[ idCategory=" + idCategory + " ]";
    }
    
}
